layui.config({
  base:'statics/js/'
}).use(['navtab'],function(){
	window.jQuery = window.$ = layui.jquery;
	window.layer = layui.layer;
    var element = layui.element();
    var navtab = layui.navtab({
		elem: '.larry-tab-box'
	});

    //iframe自适应
    $(window).on('resize', function() {
    	var $content = $('.iframe-content');
    	$content.height($(this).height() - 156);
    	$content.find('iframe').each(function() {
    		$(this).height($content.height());
    	});
    }).resize();
    $("#iframeId").load(function () {
    	var $content = $('.iframe-content');
    	var a = $(window).height() - 156;
    	var mainheight = $(this).contents().find("body").height() + 30;  
    	$content.height(mainheight>a ? mainheight:a);
    	$(this).height(mainheight>a ? mainheight:a);
    });
  
	$(function(){
		$(".menu-leaf").click(function(){
    		var $a = $(this);
    	    var href = $a.data('url');
    	    var target = $a.data('target');
    	    var icon = $a.children('i:first').data('icon');
    	    var title = $a.children('span').text();
    	    var data = {
    	          href: href,
    	          icon: icon,
    	          title: title
    	    }
    	    if("view_window" === target){
    	 	   window.open(href); 
    	    }else{
    	 	   navtab.tabAdd(data); 
    	    }
    		
    	});
	});
});

layui.use(['jquery','layer','element'],function(){
	window.jQuery = window.$ = layui.jquery;
	window.layer = layui.layer;
	var element = layui.element();

	// larry-side-menu向左折叠
	$('.larry-side-menu').click(function() {
	  var sideWidth = $('#larry-side').width();
	  if(sideWidth === 200) {
	      $('#larry-body').animate({
	        left: '0'
	      }); 
	      $('#larry-footer').animate({
	        left: '0'
	      });
	      $('#larry-side').animate({
	        width: '0'
	      });
	  } else {
	      $('#larry-body').animate({
	        left: '200px'
	      });
	      $('#larry-footer').animate({
	        left: '200px'
	      });
	      $('#larry-side').animate({
	        width: '200px'
	      });
	  }
	});
});
var IndexHandler = {
		updatePassword: function(){
			layer.open({
				type: 1,
				skin: 'layui-layer-molv',
				title: "修改密码",
				area: ['550px', '330px'],
				shadeClose: false,
				content: jQuery("#passwordLayer"),
				btn: ['修改','取消'],
				btn1: function (index) {
					var oldpwd = $("input[name='password']").val();
					var newpwd = $("input[name='newPassword']").val();
					var validpwd = $("input[name='newPwd']").val();
					var data = "oldpwd="+oldpwd+"&newpwd="+newpwd+"&validpwd="+validpwd;
					$.ajax({
						type: "POST",
					    url: "user/change-pwd",
					    data: data,
					    dataType: "json",
					    success: function(result){
					    	if(result && result.success){
								layer.close(index);
								layer.alert('修改成功', function(index){
									location.reload();
								});
							}else if(result && !result.success && result.data){
								layer.alert(result.data);
							}else{
								layer.alert(result.msg);
							}
						}
					});
	            }
			});
		}
	};